<template>
	<view>
		<input :disabled="disabled" :placeholder="placeholder" @tap="getLocation" type="text" :value="value" />
	</view>
</template>

<script>
	export default {
		props: {
			disabled: {
				type: Boolean,
				default: false
			},
			value: {
				type: String,
				required: true
			},
			placeholder: {
				type: String,
				required: true
			}
		},
		data() {
			return {

			}
		},
		methods: {
			getLocation() {
				if(this.disabled) {
					return
				}
				uni.chooseLocation({
					success: (res) => {
						this.$emit('input', res)
						this.$emit('location', res)
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
					}
					// fail(err) {
					// 	console.log(err)
					// 	if(err.errMsg == 'chooseLocation:fail auth deny') {
					// 		console.log('再次触发')
					// 		uni.showModal({
					// 			title: '提示',
					// 			content: '您还没有授权,请进行授权',
					// 			success: function(res) {
					// 				if (res.confirm) {
					// 					uni.chooseLocation({
					// 					    success: function (res) {
					// 					        console.log('位置名称：' + res.name);
					// 					        console.log('详细地址：' + res.address);
					// 					        console.log('纬度：' + res.latitude);
					// 					        console.log('经度：' + res.longitude);
					// 					    }
					// 					});
					// 				} else if (res.cancel) {
					// 					console.log('用户点击取消');
					// 				}
					// 			}
					// 		})
					// 	}
					// }
				});
			}
		}
	}
</script>

<style>
</style>
/* <!-- <template>
	<view>
		<input :placeholder="placeholder" @tap="getLocation" type="text" :value="address" />
	</view>
</template>

<script>
	export default {
		props: {	
			value: {
				type: String,
			
			}
			placeholder: {
				type: String,
				required: true
			}
		},		
		data() {
			return {
				value: {},
				address:''
			}
		},
		methods: {
			setLocation(location){
				console.log('change location')
				this.value = location
				this.address = location.address
			},
			getLocation() {
				uni.chooseLocation({
					success: (res) => {
						this.value = res
						// this.$emit('location', res)
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
						this.address = res.address
						this.$emit('change', res)
					
					}
				});
			}
		}
	}
</script>

<style>
</style> --> */
